package factory

import (
	"go_keep_learning/jtthink/design_patterns/gin_factory_decotator/model"

	"github.com/gin-gonic/gin"
)

func HandlerDecorator(h model.Hanler) gin.HandlerFunc {
	return func(c *gin.Context) {
		if res, err := h(c); err != nil {
			c.AbortWithStatusJSON(400, gin.H{"error": err.Error()})
		} else {
			c.JSON(200, res)
		}
	}

}

type HandlerType int

const (
	UserHandlerType = iota
	AnimalHanlerType
)

func CreateHandler(t HandlerType) gin.HandlerFunc {
	switch t {
	case UserHandlerType:
		return func(c *gin.Context) {
			model.GetUserInfo(c)

		}

		//return HandlerDecorator(model.GetUserInfo)
	}
	return nil
}
